package com.example.hello.client.Column;

import com.example.hello.BootstrapColumn;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

import java.util.Iterator;

@Connect(BootstrapColumn.class)
public class BootstrapColumnConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapColumn.class);
    }

    @Override
    public VBootstrapColumn getWidget() {
        return (VBootstrapColumn) super.getWidget();
    }

    @Override
    public BootstrapColumnState getState() {
        return (BootstrapColumnState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapColumnState state = getState();

        VBootstrapColumn column = getWidget();

        Iterator<Connector> itr = state.getWidgets().iterator();
        while (itr.hasNext()) {
            column.add(((ComponentConnector) itr.next()).getWidget());
        }
    }

}
